﻿using AnesSystem.Model;
using AnesSystem.Models;
using AnesSystem.Udp;
using AnesSystem.Util;
using AnesSystem.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AnesSystem.Controls.Statistics
{
    /// <summary>
    /// OperationNoticeCtrl.xaml 的交互逻辑
    /// </summary>
    public partial class DrugListCtrl : FunctionAndTableCtrl
    {

        #region Variables

        #endregion

        #region Constructor
        public DrugListCtrl()
        {
            InitializeComponent();
            this.DataContext = DrugListCtrlViewModel.Instance;
            PageOrientation = System.Printing.PageOrientation.Landscape;
            this.Loaded += OperationNoticeCtrl_Loaded;
        }
        #endregion

        #region Properties


        #endregion

        #region 依赖属性


        #endregion

        #region Event


        #endregion

        #region PrivateMethods


        //public List<PatientLinkModel> GetPatientLink()
        //{
        //    return DrugListCtrlViewModel.Instance.GetPatientLink();
        //}

        #endregion

        #region Public/ProtectedMethods

        public override void PrintVisual()
        {
            p.PrintTicket.PageOrientation = PageOrientation;
            List<FrameworkElement> temp = new List<FrameworkElement>();
            foreach (var item in DrugListCtrlViewModel.Instance.DisplayOprList)
            {
                temp.Add(item);
            }
            Print(temp);
        }

        public override void Refesh()
        {
            DrugListCtrlViewModel.Instance.Refresh();
            //try
            //{
            //    Task.Factory.StartNew(delegate
            //    {
            //        Dispatcher.Invoke(delegate
            //        {
                        
            //            MainPageCommonViewModel.Instance.WaitCtrlVisibility = Visibility.Collapsed;
            //        });
            //        return;
            //    });
            //    MainPageCommonViewModel.Instance.WaitCtrlVisibility = Visibility.Visible;
            //}
            //catch (Exception ex)
            //{
            //    Common.LogHelper.Error(this.GetType(), ex);
            //}
            
        }

        #endregion

        #region EventHandlers
        

        private void OperationNoticeCtrl_Loaded(object sender, RoutedEventArgs e)
        {
            FunctionListHeaderCtrlViewModel.Instance.DisplayButton(true, FunctionListButton.打印, FunctionListButton.刷新);
        }

        #endregion

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            DrugListCtrlViewModel.Instance.Refresh(new DateTime(_startDate.SelectedDateTime.Year, _startDate.SelectedDateTime.Month, _startDate.SelectedDateTime.Day), new DateTime(_endDate.SelectedDateTime.Year, _endDate.SelectedDateTime.Month, _endDate.SelectedDateTime.Day));
        }
    }
}
